X3D 3D Everywhere

VRML -> X3D

Introducing
X3D



X3D XML Syntax Overview (2)


The Actual Transcoding

Now, a quick study of the existing VRML97 definitions and syntax, before developing the XML encoding.


Basic VRML97 Syntax
Shape

VRML97 Spec IDL:

  Shape { 
    exposedField SFNode appearance   NULL
    exposedField SFNode geometry     NULL
  }

X3D Spec IDL:

  Shape : ShapeNodeType {
    field [in, out]  SFNode  appearance  NULL;
    field [in, out]  SFNode   geometry   NULL;
  }

Changed Notation:

        X3D            VRML97

  field [in, out] = exposedField

         field [] = field (initialize only)

       event [in] = eventIn 

      event [out] = eventOut

Definition:

  NodeName : AbstractionNode {
  field|event [in,out|in|out] VarType NodeOrFieldName 
                                      NodeOrFieldDefault|NULL 
                                       [min,max|list]; 
  ...
  }

    field|event = field or event  
       [in,out] or [in] or [out] access, 
         VarType = Node/Field Type from official list, 
          Node or field name from official list, 
           Node/field initial or default value or NULL, and,  
            [min,max|list] used for Fields to show  
            acceptable value = 
              min.max = numeric range. Examples: 
                 [0,1] = range 0 to 1 
                 (-inf,inf) = any signed number 
                 [-1,inf) = any number egt -1  
                 (0,1] = allow value of one but not zero 
              list = choice of values. Example: 
                 [TRUE|FALSE] = either TRUE or FALSE is accepted.

For Example:

  Appearance : X3DNode { 
    field [in,out]  SFNode  material         NULL;
    field [in,out]  SFNode  texture          NULL; 
    field [in,out]  SFNode  textureTransform NULL; 
  }

        (Nodes don't use the [min,max|list] definition.)

  Material : MaterialNode { 
    field [in, out]  SFFloat  ambientIntensity 0.2         [0,1]; 
    field [in, out]  SFColor  diffuseColor     0.8 0.8 0.8 [0,1];
    field [in, out]  SFColor  emissiveColor    0 0 0       [0,1];
    field [in, out]  SFFloat  shininess        0.2         [0,1]; 
    field [in, out]  SFColor  specularColor    0 0 0       [0,1];  
    field [in, out]  SFFloat  transparency     0           [0,1];  
  } 

        [0,1] applies to each numeric component of the value. 

Shape, Appearance.
The Shape node has two fields, appearance and geometry, which are used to create rendered objects in the world. The appearance field contains an Appearance node that specifies the visual attributes (e.g., material and texture) to be applied to the geometry. The geometry field contains a geometry node. The specified geometry node is rendered with the specified appearance nodes appled.

Basic VRML97 Syntax
appearance texture nodes

Texturing :

   ImageTexture
   MovieTexture       
   PixelTexture
 
  ImageTexture : TextureNodeType { 
    field [in, out]  MFUrl   url      [NULL] ["urn"]  
    field []         SFBool  repeatS; TRUE   [TRUE|FALSE]
    field []         SFBool  repeatT; TRUE   [TRUE|FALSE]
  }

  MovieTexture : TextureNodeType { 
    field [in, out]  SFBool  loop              FALSE
    field [in, out]  SFFloat speed             1.0    [-∞,∞];
    field [in, out]  SFTime  startTime         0      [-∞,∞];
    field [in, out]  SFTime  stopTime          0      [-∞,∞];
    field [in, out]  MFUrl   url               [NULL] ["urn"];
    field []         SFBool  repeatS           TRUE   [TRUE|FALSE]
    field []         SFBool  repeatT           TRUE   [TRUE|FALSE]
    event [out]      SFTime  duration_changed;
    event [out]      SFBool  isActive;
  }


TextureTransform : TextureTransformNodeType { 
  field [in, out]  SFVec2f  center      0 0  [-∞,∞];
  field [in, out]  SFFloat  rotation    0    [-∞,∞];
  field [in, out]  SFVec2f  scale       1 1  [-∞,∞];
  field [in, out]  SFVec2f  translation 0 0  [-∞,∞];
}

Texture can contain ImageTexture, MovieTexture, or PixelTexture nodes.
Default texture mapping.

Basic VRML97 Syntax
geometry

  field [in, out] SFNode geometry NULL

  Box 
  Cone 
  Cylinder 
  ElevationGrid 
  Extrusion 
  IndexedFaceSet 
  IndexedLineSet 
  PointSet 
  Sphere 
  Text 
  Geometry nodes created from PROTOs or EXTERNPROTOs 
  Humanoid
  Parameteric
  Volumetric
  Hypermetric
  Hypermultimetric
  Plus new stuff ...

There is not now or was ever a node named geometry. It is a container field for one of the geometry nodes: Box, Cone, Cylinder, ElevationGrid, Extrusion, IndexedFaceSet, IndexedLineSet and all.

Basic VRML97 Syntax
IndexedFaceSet

 

  IndexedFaceSet : GeometryNodeType  { 
    event [in]      MFInt32  set_colorIndex;
    event [in]      MFInt32  set_coordIndex;
    event [in]      MFInt32  set_normalIndex;
    event [in]      MFInt32  set_texCoordIndex;
    field [in, out] SFNode   color;             NULL
    field [in, out] SFNode   coord;             NULL
    field [in, out] SFNode   normal;            NULL
    field [in, out] SFNode   texCoord;          NULL
    field []        SFBool   ccw;               TRUE           [-1|int];
    field []        MFInt32  colorIndex;        [coordIndex]   [-1|int];
    field []        SFBool   colorPerVertex;    TRUE           [TRUE|FALSE]
    field []        SFBool   convex;            TRUE           [TRUE|FALSE]
    field []        MFInt32  coordIndex;        [NULL]         [-1|int]
    field []        SFFloat  creaseAngle;       0              [0,∞)
    field []        MFInt32  normalIndex;       [coordIndex]   [-1|int]
    field []        SFBool   normalPerVertex;   TRUE           [TRUE|FALSE]
    field []        SFBool   solid;             TRUE           [TRUE|FALSE]
    field []        MFInt32  texCoordIndex;     [coordIndex]   [-1|int]
  }

Each face of the IndexedFaceSet shall have:

  1. at least three non-coincident vertices,
  2. vertices that define a planar polygon,
  3. vertices that define a non-self-intersecting polygon.

Otherwise, results are undefined.

indexed Face Set coordinates, textcoordinates, normals, and indices
  Color : ColorNodeType { 
    field [in, out]  MFColor  color [NULL]  [0,1]
  }

  Coordinate : CoordinateNodeType { 
    field [in, out]  MFVec3f  point  [NULL]  [-∞,∞]
  }

  Normal : NormalNodeType { 
    field [in, out]  MFVec3f  vector [computed]  [-∞,∞]
  }

  TextureCoordinate : TextureCoordinateNodeType { 
    field [in, out]  MFVec2f  point  [computed]  [-∞,∞]
  }

Here is the IndexedfaceSet IDL.
It shows that the Color, Coordinate, Normal, TextureCoordinate are nodes.
If color, normal, texCoord points, or colorIndex, texCoordIndex, or normalIndex are NULL, then coord point or coordIndex is used.

Basic VRML97 Syntax
A Result

  Shape { 
    appearance         Appearance { 
      material           Material { 
        ambientIntensity   0.2         
        diffuseColor       0.8 0.8 0.8 
        emissiveColor      0 0 0       
        shininess          0.2         
        specularColor      0 0 0       
        transparency       0           
      }
      texture            ImageTexture { 
        url                ["somePic.jpeg"]
        repeatS            TRUE
        repeatT            TRUE
      }
      textureTransform   TextureTransform { 
        center             0 0     
        rotation           0      
        scale              1 1    
        translation        0 0    
      }
    }
    geometry          IndexedFaceSet {  
      ccw               TRUE 
      convex            TRUE 
      creaseAngle       0  
      solid             TRUE 
      coord Coordinate  {point[ x y z, ... ] }  
      coordIndex       [ v1 v2 v3 ... -1, ... ] 
      colorPerVertex    TRUE   
      color             Color {color [r g b, ... ] }   
      colorIndex       [ v1 v2 v3 ... -1, ...]                               
      texCoord TextureCoordinate {point [ x y z, ... ]}  
        texCoordIndex    [ v1 v2 v3 ... -1, ...] 
      normalPerVertex   TRUE         
      normal            Normal {vector[x y z, ... ] }  
        normalIndex      [ v1 v2 v3 ... -1, ... ]        
    }
  }

The coord Coordinate point gives the x,y,z for each vertex.
The coordIndex identifies the vertices in the polygon by order in coord Coordinate point,
then closing the polygon with -1.

Basic XML Syntax

Elements contain Content and Attributes

The Basic Content Tagset:

        <tagname attr1='string' > 
          ... content ...
        </tagname >  

        attribute is name and value pair: name='value'

The Empty Element:

        <tagname attr2="string' /> 

Elements can be Content:

        <tag1> 
          <tag2 />
          <tag3> 
            <tag4 />
          </tag3>
        </tag1> 

XML Namespaces:

        tagname = namespace:tagname 

        attrname = namespace:attrname 

          value space - lexical space - facets 

The tagset for a basic element consists of a start tag and an end tag.
Everything between the start and end tags is called content.
Content can be another set of tags.
If the element does not contain content, only attributes,
the begin and end tags can be combined as shown in this example of an empty element.

Elements can be content: Here the element called tag1 contains the empty element called tag2, along with the element called tag3, which in turn contains the element called tag4.

The tagname and attrname (atribute name) actually consist of two parts, an XML namespace, and the tagname. The XML namespace is defined by the XML schema and is a slightly different concept than the typical use of the term in programmng because it allows definiton of the structure of the subject element. And an amazing thing about it is that some item way down in the middle of a structure can obtain its identity from a completely different environment than any other items in the structure.

X3D XML Shape

X3D Spec IDL:

  Shape : ShapeNodeType {
    field [in, out]  SFNode  appearance  NULL
    field [in, out]  SFNode  geometry    NULL
  }

X3D XML Encoding:

  <Shape > 

     ...

  </Shape >


  <Shape > 
     appearance 
     geometry
  </Shape >

So that is what it begins to look like. We have a Shape element and place to add appearance and geometry. Now let's look at the X3D XML Schema for more detail.

X3D XML Shape Schema

	<xsd:element name="Shape">
		<xsd:element ref="Appearance"/>
		<xsd:element ref="IndexedFaceSet" />
	</xsd:element>

Yes, that is a bit too simple, we really need:

	<xsd:element name="Shape">
                <xsd:attribute name="DEF" type="IDREF"/>
		<xsd:element ref="Appearance"/>	
		<xsd:group ref="GeometryContentModel"/>
	</xsd:element>

	<xsd:group name="GeometryContentModel">
		<xsd:choice>
			<xsd:element ref="IndexedFaceSet"/>
			<xsd:element ref="IndexedLineSet"/>
			<xsd:element ref="PointSet"/>
                  ...
			<xsd:element ref="Nurbs"/>
		</xsd:choice>
	</xsd:group>

XML Schema Definition of Group:

        <group name = NCName>
            Content: ((all | choice | sequence))
        </group>

Shape, GeometryContentModel, Appearance

X3D XML IndexedFaceSet Schema

And the Schema looks like:

<xsd:element name="IndexedFaceSet">
   <xsd:attribute name="DEF" type="IDREF"/>
   <xsd:attribute name="ccw" type="Boolean" default="TRUE" />
   <xsd:attribute name="convex" type="Boolean"default="TRUE" />
   <xsd:attribute name="creaseAngle" type="Float" default="0" />
   <xsd:attribute name="colorPerVertex" type="Boolean" default="TRUE" />
   <xsd:attribute name="normalPerVertex" type="Boolean" default="TRUE" />
   <xsd:attribute name="solid" type="Boolean" default="TRUE" />
   <xsd:attribute name="coordIndex" type="Integers"/>
   <xsd:attribute name="colorIndex" type="Integers"/>
   <xsd:attribute name="normalIndex" type="Integers"/>
   <xsd:attribute name="texCoordIndex" type="Integers"/>
   <xsd:element name="Coordinate">
      <xsd:attribute name="point" type="Vector3FloatArray"/>
   </xsd:element>
   <xsd:element name="ColorNode">
      <xsd:attribute name="color" type="Colors"/>
   </xsd:element>
   <xsd:element name="Normal">
      <xsd:attribute name="vector" type="Vector3FloatArray"/>
   </xsd:element>
   <xsd:element name="TextureCoordinate">
      <xsd:attribute name="point" type="Vector2FloatArray"/>
   </xsd:element>
</xsd:element>

From the diagram:

   GeometryNodeType
    IndexedFaceSet
     ccw='Boolean'
     colorIndex='Integers'
     colorPerVertex='Boolean'
     convex='Boolean'
     coordIndex='Integers'
     creaseAngle='Float'
     normalIndex='Integers'
     normalPerVertex='Boolean'
     solid='Boolean'
     texCoordIndex='Integers'
     GeometricPropertyNode
      ColorNodeType
      CoordinateNodeType
      NormalNodeType
      TextureCoordinateNodeType

   GeometricPropertyNodeType 
    ColorNodeType
     ColorNode color='Colors'
    CoordinateNodeType 
     Coordinate point='Vector3FloatArray 
    NormalNodeType 
     Normal vector='Vector3FloatArray'
    TextureCoordinateNodeType 
     TextureCoordinate point='Vector2FloatArray' 

Gives us:

 <IndexedFaceSet
    ccw='Boolean'
    normalPerVertex='Boolean'
    colorPerVertex='Boolean'
    convex='Boolean'
    solid='Boolean'
    creaseAngle='Float'
    coordIndex='Integers'
    colorIndex='Integers'
    normalIndex='Integers'
    texCoordIndex='Integers' >
    <Coordinate point='Vector3FloatArray />
    <ColorNode color='Colors' />
    <Normal vector='Vector3FloatArray' />
    <TextureCoordinate point='Vector2FloatArray' />
 </IndexedFaceSet> 

element name="IndexedFaceSet"
* coordIndex used if colorIndex or normalIndex is NULL.
* default texCoordIndex provided if NULL.

web3d x3d syntax

Welcome to a discussion of the XMLization and DOMification of VRML.

Back | Next

Some small steps toward WWWWorld Wide WebHyperMultiMedia

©2002 Williams Publications/hypermultimedia.com

rights reserved - 02/18/02 03/11 03/13 03/21 03/24 03/25 03/26 03/27 04/04